<%@ page import="java.util.List" %>
<%@ page import="com.syz.web.pojo.Student" %>
<%@ page import="com.syz.web.util.PageInfo" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>student</title>
    <link rel="stylesheet" href="static/bootstrap-3.4.1-dist/css/bootstrap.css">
</head>
<body>
<%
    List<Student> students= (List<Student>) request.getAttribute("list");
%>
<%
    PageInfo<Student> pageInfo = (PageInfo<Student>) request.getAttribute("pageInfo");
%>
    <a class="btn btn-primary" href="<%=request.getContextPath()%>/Student/student_add.jsp">添加</a>
    <table class="table table-striped table-bordered table-hover table-condensed">
        <tr>
            <td>ID</td>
            <td>名字</td>
            <td>年龄</td>
            <td>性别</td>
            <td>班级</td>
            <td>地址</td>
            <td>编辑</td>
            <td>删除</td>
        </tr>
        <%
            for(Student student:pageInfo.getList()){
        %>
                <tr>
                    <td><%=student.getId()%></td>
                    <td><%=student.getName()%></td>
                    <td><%=student.getAge()%></td>
                    <td><%=student.getGender()%></td>
                    <td><%=student.getBanjiId()==null?"":student.getBanjiId()%></td>
                    <td><%=student.getAddress()==null?"":student.getAddress()%></td>
                    <td><a href="<%=request.getContextPath()%>/student?method=getStudentUpdatePage&id=<%=student.getId()%>">编辑</a></td>
                    <%--<td><a href="<%=request.getContextPath()%>/deleteStudent?id=<%=student.getId()%>">删除</a></td>--%>
                    <td><a href="<%=request.getContextPath()%>/student?method=deleteById&id=<%=student.getId()%>">删除</a></td>
                </tr>
        <%
            }
        %>
    </table>
<nav aria-label="Page navigation">
    <ul class="pagination">
        <%
            if (pageInfo.getPageNo() == 1) {
        %>
        <li class="disabled">
            <a href="#" aria-label="Previous">
                <span aria-hidden="true">&laquo;</span>
            </a>
        </li>
        <%
        } else {
        %>
        <li>
            <a href="<%=request.getContextPath()%>/student?method=selectByPage&pageNo=<%=pageInfo.getPageNo()-1%>" aria-label="Previous">
                <span aria-hidden="true">&laquo;</span>
            </a>
        </li>
        <%
            }
        %>

        <%
            for (int i = 1; i <= pageInfo.getTotalPage(); i++) {
                if (i == pageInfo.getPageNo()) {
        %>
        <li class="active"><a href="#"><%=i%></a></li>
        <%
        } else {
        %>
        <li><a href="<%=request.getContextPath()%>/student?method=selectByPage&pageNo=<%=i%>"><%=i%></a></li>
        <%
                }
            }
        %>
        <%
            String nextUrl=request.getContextPath()+"/student?method=selectByPage&pageNo="+(pageInfo.getPageNo()+1);
        %>
        <li class="<%=pageInfo.getPageNo()==pageInfo.getTotalPage()?"disabled":""%>">

            <a href="<%=pageInfo.getPageNo()==pageInfo.getTotalPage()?"#":nextUrl%>" aria-label="Next">
                <span aria-hidden="true">&raquo;</span>
            </a>

        </li>
    </ul>
</nav>
</body>
</html>
